<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item >
        <el-select v-model="optionsVal" placeholder="查询条件">
          <el-option v-for="item in options" 
           :key="item.label"
           :label="item.value"
           :value="item.label"> 
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-input
          v-model="keyword"
          placeholder="查询值"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
        <el-button v-if="isAuth('generator:tmessagenotice:save')" type="primary" @click="addOrUpdateHandle()">发布消息</el-button>
        <el-button v-if="isAuth('generator:tmessagenotice:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>
        <el-button
          v-if="isAuth('generator:tmessagenotice:dealwith')"
          type="success"
          @click="dealwith"
          >提交反馈</el-button
        >
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        prop="publishNo"
        header-align="center"
        align="center"
        label="发布人编号">
      </el-table-column>
      <el-table-column
        prop="publishName"
        header-align="center"
        align="center"
        label="发布人姓名">
      </el-table-column>
      <el-table-column
        prop="publishContent"
        header-align="center"
        align="center"
        label="消息内容">
      </el-table-column>
      <el-table-column
        prop="receiveNo"
        header-align="center"
        align="center"
        label="接收人编号">
      </el-table-column>
      <el-table-column
        prop="receiveName"
        header-align="center"
        align="center"
        label="接收人姓名">
      </el-table-column>
      <el-table-column
        prop="publishTime"
        header-align="center"
        align="center"
        label="发布时间">
      </el-table-column>
      <el-table-column
        prop="checkResult"
        header-align="center"
        align="center"
        label="消息状态">
      </el-table-column>
      <el-table-column
        prop="messageType"
        header-align="center"
        align="center"
        label="消息类别">
      </el-table-column>
      <el-table-column
        prop="messageContent"
        header-align="center"
        align="center"
        label="消息批注">
      </el-table-column>
      <el-table-column
        prop="examGrade"
        header-align="center"
        align="center"
        label="考试成绩">
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" v-if="isAuth('generator:tmessagenotice:update')" @click="addOrUpdateHandle(scope.row.id)">处理</el-button>
          <el-button type="text" size="small" v-if="isAuth('generator:tmessagenotice:delete')" @click="deleteHandle(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
  import AddOrUpdate from './tmessagenotice-add-or-update'
  export default {
    data () {
      return {
        dataForm: {
          key: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false,
      options: [
      {
          value: "发布人编码",
          label: "publish_code",
        },
        {
          value: "发布人姓名",
          label: "publish_name",
        },
        {
          value: "接收人编码",
          label: "receive_code",
        },
        {
          value: "接收人姓名",
          label: "receive_name",
        },
        {
          value: "消息状态",
          label: "check_result",
        } ,
        {
          value: "消息类别",
          label: "message_type",
        }  ,
        {
          value: "考试成绩",
          label: "exam_grade",
        } 
      ],
      value: "",
      param: "",
      optionsVal: '',
      keyword: ''
      }
    },
    components: {
      AddOrUpdate
    },
    activated () {
      this.getDataList()
    },
    methods: {
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true;
      // this.param =param;
      
      let custParams = this.$http.adornParams({
          page: this.pageIndex,
          limit: this.pageSize
        });
        if(this.optionsVal != null && this.keyword != null){
          custParams[this.optionsVal] = this.keyword;
        }
        this.$http({
          url: this.$http.adornUrl('/notice/tmessagenotice/list'),
          method: 'get',
          params: custParams
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      
      dealwith(){
        console.log(this.dataListSelections)
          this.$http({
            url: this.$http.adornUrl('notice/tmessagenotice/dealwith'),
            method: 'post',
            data: this.dataListSelections
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })

      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id)
        })
      },
      // 删除
      deleteHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.id
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/notice/tmessagenotice/delete'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      }
    }
  }
</script>
